﻿using System;
using System.Collections.Generic;
using System.Text;
using Tao.OpenGl;
using Tao.Platform.Windows;
using System.Diagnostics;
using System.Drawing;

namespace TaoGL_UserControl
{
    class PianoKeyEnd:Tex2DUV
    {
        string[] ImgTable = 
        {
            "type_01_normalbutton_060.tga","type_01_specialbutton_060.tga",
        };
        //======================================================================
        const int conRunMaxTime = 400; //1秒

        private int RunEndTm = 0;   //取得時間

        public PianoKeyEnd()
        {
            foreach (string fp in ImgTable)
                TexMgr.LoadTextureEx(PathMgr.Img + fp);
            ChangeImage(0);
            Rectangle rect = TexMgr.GetTextureInfo(ImgTable[0]).rectange;
            SetSize(rect.Width, rect.Height);
        }
        //======================================================================
        public void ChangeImage(int num)
        {
            if (num < ImgTable.Length && num >= 0)
                TextureIndex = TexMgr.GetTextureInfo(ImgTable[num]).Index;
            else
                Debug.WriteLine("PianoKeyEnd Chage Image Num Error:" + num);
        }
        //======================================================================
        //Mode代表使用那一種顏色
        public void Run(int mode)
        {
            if (mode == 0)
                ChangeImage(0);
            else
                ChangeImage(1);

            RunEndTm = TimeMgr.GetNowLocalTimeMilliseconds() + conRunMaxTime;

        }
        //======================================================================
        public override void Process(int tm)
        {
            int NowTM = TimeMgr.GetNowLocalTimeMilliseconds();
            float ActPer = 0.0f;
            if (RunEndTm > NowTM)
            {
                ActPer = (float)(RunEndTm - NowTM) / (float)conRunMaxTime;
            }
            Debug.WriteLine("ActPer" + ActPer);            
            SetOpacity(ActPer);
        }
        //======================================================================

    }
}
